var express = require("express");
var ssr = require("./ssr.js");
// 环境变量配置
//
const ev = require('./common/index')
// 获取当前分支名称
const app = express();
// 案例列表
app.get("/getCaseList", async (req, res, next) => {
  try {
    const { html, ttRenderMs } = await ssr(
      `${ev.baseUrl}/html/caseListSSR.html`
    );
    res.set(
      "Server-Timing",
      `Prerender;dur=${ttRenderMs};desc="Headless render time (ms)"`
    );
    return res.status(200).send(html); // Serve prerendered page as response.
  } catch (e){
    console.info(e)
  }
});
// 新闻列表
app.get("/getNewList", async (req, res, next) => {
  try {
    const { html, ttRenderMs } = await ssr(
      `${ev.baseUrl}/html/aboutUsSSR.html`
    );
    res.set(
      "Server-Timing",
      `Prerender;dur=${ttRenderMs};desc="Headless render time (ms)"`
    );
    return res.status(200).send(html); // Serve prerendered page as response.
  } catch (e){
    console.info(e)
  }
});

app.listen(8080, () => console.log("Server started. Press Ctrl+C to quit"));
